﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace GJB.MVVMLesson.Base
{
    public class WindowManager
    {
        static Dictionary<string, WinEntity> _windows = new Dictionary<string, WinEntity>();

        public static void Register(Type type,Window window)
        {
            if (!_windows.ContainsKey(type.Name))
            {
                _windows.Add(type.Name, new WinEntity { Type = type,owner = window});
            }
        }

        public static void ShowDialog(string winKey)
        {
            if (_windows.ContainsKey(winKey))
            {
                Type type = _windows[winKey].Type;
                var win = (Window)Activator.CreateInstance(type);
                win.Owner = _windows[winKey].owner;
                win.ShowDialog();
            }
        }
    }

    public class WinEntity
    {
        public Type Type { get; set; }
        public Window owner { get; set; }
    }
}
